import createAxios, {getUrl} from '/@/utils/axios'
import { useUserInfo } from '/@/stores/userInfo'

export const apiUrl = '/api/ai.message';

// 获取消息
export function getMessage(group_id: number) {
    return createAxios({
        url: apiUrl + '/index',
        method: 'get',
        params: {
            group_id: group_id
        },
    })
}

// 删除消息
export function delMessage(params: any) {
    return createAxios({
        url: apiUrl + '/delete',
        method: 'post',
        data: params
    })
}


// 发送消息Source类型数据headers
// export function sendText(params: any) {
//     return createAxios({
//         url: apiUrl + '/send_text',
//         method: 'post',
//         data: params
//     })
// }
export function sendText(params: any) {
    const userInfo= useUserInfo();
    return fetch(getUrl() + apiUrl + '/send_text', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Ba-User-Token': userInfo.token,
        },
        body: JSON.stringify(params)
    })
}

export function sendText2(group_id: number, content: string) {
    // 获取Ba-User-Token
    const userInfo= useUserInfo();
    return new EventSource(getUrl() + apiUrl + '/send_text');
}
